package algorithm;

import java.util.Arrays;

public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = {8, 2, 5, 9, 7};
        bubbleSort_v1(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }

    private static void bubbleSort_v1(int[] arr) {
        //Arrays.sort(arr);
        //String s = Arrays.toString(arr);
        //System.out.println("s = " + s);
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                int temp = 0;
                if (arr[j] < arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}

